package com.lsh.oms.provider.common.rest;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.core.MultivaluedMap;
import java.io.IOException;

/**
 * Created by huangdong on 16/7/15.
 */
public class CustomRestFilter implements ContainerRequestFilter {

	private static Logger logger = LoggerFactory.getLogger(CustomRestFilter.class);
	@Override
    public void filter(ContainerRequestContext context) throws IOException {
        MultivaluedMap<String, String> map = context.getHeaders();
        logger.info("api-version -- " + map.getFirst("api-version") + "random -- "+ map.getFirst("random") + "platform -- "+ map.getFirst("platform"));
        String apiversion = map.getFirst("api-version");
        String random = map.getFirst("random");
        String platform = map.getFirst("platform");
//      String secretType = map.getFirst("secret-type");
//      String sign = map.getFirst("sign");
        if (StringUtils.isAnyBlank(apiversion,random,platform)) {
            logger.info("apiversion : random : platform" + apiversion + ":" + random + ":" + platform);
//            throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).entity("request forbidden!").build());
        }
    }
}
